package com.example.springMVC.commons;

import org.springframework.http.HttpStatus;

import java.io.Serializable;

public class Result implements Serializable {

    Integer code;
    String msg;
    Object data;

    public Result() {
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static Result success (String msg, Object data) {
        return new Result(HttpStatus.OK.value(),msg,data);
    }
    public static Result success(Object data){
        return new Result(HttpStatus.OK.value(),"请求成功",data);
    }
    public static Result success(){
        return new Result(HttpStatus.OK.value(),"请求成功","null");
    }

    public static Result error(String msg){
        return new Result(HttpStatus.INTERNAL_SERVER_ERROR.value(),msg,null);
    }
    public static Result error(){
        return new Result(HttpStatus.INTERNAL_SERVER_ERROR.value(),"系统异常",null);
    }
}
